package com.ambow.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ambow.model.Admin;
import com.ambow.service.AdminService;
import com.ambow.service.impl.AdminServiceImpl;

@SuppressWarnings("serial")
public class AdminLoginServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		System.out.println("servlet");
		String account = request.getParameter("account");
		String pwd = request.getParameter("pwd");

		System.out.println("account=" + account);
		System.out.println("pwd=" + pwd);

		AdminService service = new AdminServiceImpl();
		Admin loginUser = service.adminLogin(account, pwd);

		if (loginUser == null) {
			/*response.sendRedirect("../pages/admin/adminLogin.jsp");//相对路径*/
		  System.out.println("密码错误");
		  response.sendRedirect("/Book_System/pages/admin/adminLogin.jsp");//绝对地址    /
		}
		else {
			request.getRequestDispatcher("/Book_System/pages/static/index.jsp").forward(
					request, response);
		}

	}

}
